GBML manual / Rooms

What a region does in the game

Each region's tile sets, song and background color, a shroud on some pieces, and the two calls that say which region the player is in.

A world is drawn as regions: the named areas you paint in the Regions list of World Properties (a forest, a desert, an old road). Each piece of the world, 2 x 2 screens, belongs to exactly one region. This is what the game does with them while the player walks.

Tile sets

Each part of the world loads the tiles of its own region. Where two regions meet, the parts at the border carry the tiles of both, because the half screen you can see past the edge is drawn from the neighbor. Parts that touch the same regions share their tiles (they are stored once in the game), and walking between two of them loads no tiles at all. Walking into a part that has other tiles loads them; the build warns, in the Problems list, when a part at a border needs more tiles or colors than the console can show at once, or more than one frame can load.

The world's own tile set is in every part. Keep it small, and put the sets only some regions use in those regions.

Music

A region can have a song. When the player walks into a region whose song is not the one playing, the game changes the song the way music_fade_to does: the old song fades out, then the new one fades in. A region with no song leaves the music alone, so the song of the region before keeps playing. Songs your code starts yourself are not touched until the player crosses into a region with a song of its own.

When the player steps back out of a house into the region, the region's song comes back if the house played another one, and it simply keeps playing, without starting over, if the house played nothing or the same song. region_set_music gives the region another song for the rest of the game; the new song is kept with the game's save.

Background color

A region can have its own background color. When the player walks into a region with another color, the color changes smoothly over about half a second. Going somewhere with world_go or a door shows the new color at once.

Shroud

Draw Shroud in the Regions section of World Properties darkens pieces of the world, whatever their regions are. A shrouded piece is a shrouded room: it is dark, and lights cut holes in it. When the player walks from a shrouded piece into a lit one the darkness fades out over about half a second, and from a lit piece into a shrouded one it fades in the same way: never a sudden flash at the border. A world with a shrouded piece uses one of the console's four background layers for the dark in every part, lit ones too, so a part of such a world can have one less layer of its own.

The house rule

The game remembers the last region the player was in. A region event happens only when the player arrives in a different region than that one. So walking into a house (a room that is not part of the world) and coming back out into the same region is not a change, and a heads-up display that says the region's name keeps saying "Crypt" inside the crypt's houses. Coming out of the house into another region is a change, and so is going to another world with world_go (the region in the old world is left, one in the new world is entered). The first region the player arrives in when the game starts is a change too, so a game always hears about the region it starts in.

What your code can ask

What an object can do

An object can have a Region Entered and a Region Exited event in its event list. They run once for every instance of the object when the player changes region, so a weather object, a door or a light can answer without any object asking every frame.

What a cutscene can do

A cutscene can start when the player enters a region: in the Cutscenes tab pick Entering a region as its trigger and choose the region. "Once" starts it the first time the player arrives there and never again (the game remembers it in its save, like a cutscene that starts on entering a room); "Every time" starts it at every arrival.

A world with one region, no song, no shroud and one background color costs the game nothing for any of this.

Regions in a long room

A room longer or taller than one screen can be cut into regions too: the Regions section of Room Properties works for it as well, with the same tools as a world's (Draw Shroud and the background color are only for worlds: in a room they are grayed). The game does the same things with them, with one difference: a long room is not loaded in parts, so the game looks at the player instead. The player of a long room is the object the camera follows (the one you gave to camera_follow). Each frame, before the Step events, the game checks which region of the room that object stands in. When it is a different one than the last region the player was in, that is a change, exactly as in a world.

A long room whose regions have no song, and whose code and objects never ask about regions, costs the game nothing for any of this. Regions in a long room explains how to make them fit, with pictures.

See also: region_nameregion_enteredregion_exitedregion_currentregion_previousregion_atregion_musicregion_set_musicregion_enterregion_exitworld_currentWhat a world remembersRegions in a long room